package com.athena.controller 
{
	import com.adobe.serialization.json.JSON;
	import com.athena.components.TextHolder;
	import com.athena.external.feed.MainMovie;
	import flash.display.Shape;
	import flash.events.MouseEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.text.TextFormat;
	/**
	 * ...
	 * @author ...
	 */
	public class FeedBack extends MainMovie
	{
		private var txt : TextHolder;
		private var hint:String = "Những ý kiến có chất lượng sẽ được nhận quà từ admin của 68Blue :)";
		public function FeedBack() 
		{
			var glow:GlowFilter = new GlowFilter();
			glow.color = 0x000000;
			glow.alpha = 0.5;
			glow.blurX = 10;
			glow.blurY = 10;
			glow.quality = BitmapFilterQuality.MEDIUM;

			filters=[glow];
			
			var _w : Number = width; var _h : Number = height;
			var rectangle:Shape = new Shape();
			rectangle.graphics.beginFill(0x000000, 1);
			rectangle.graphics.drawRect((_w - Main.getInstance().config.demension.x) / 2, (_h - Main.getInstance().config.demension.y) / 2, Main.getInstance().config.demension.x, Main.getInstance().config.demension.x);
			rectangle.alpha = 0.2;
			rectangle.graphics.endFill();
			addChild(rectangle);
			setChildIndex(rectangle, 0);
			
			this.x = (Main.getInstance().config.demension.x - _w) / 2;
			this.y = (Main.getInstance().config.demension.y - _h) / 2;
			
			var tf  :TextFormat = new TextFormat;
			tf.font = "Tahoma";
			tf.size = 14;
			
			txt = new TextHolder(hint, tf);
			txt.maxChars = 500;
			txt.multiline = true;
			txt.wordWrap = true;
			txt.width = 373; txt.height = 137;
			txt.x = 14; txt.y = 48;
			addChild(txt);
			
			close_btn.addEventListener(MouseEvent.CLICK, close);
			accept_btn.addEventListener(MouseEvent.CLICK, send);
		}
		
		private function close(e  : MouseEvent) : void {
			close_btn.removeEventListener(MouseEvent.CLICK, close);
			accept_btn.removeEventListener(MouseEvent.CLICK, send);
			this.parent.removeChild(this);
		}
		
		private function send(e : MouseEvent) : void {
			var text : String = txt.text;
			if (text == "" || text == hint) {
				Main.getInstance().stage.focus = txt;
				return;
			}
			close(null);
			var obj : Object = new Object() ;
			obj.evt = "15" ;
			obj.T = 7 ;
			obj.NN = "68Blue.admin" ;
			obj.D = text;
			Main.getInstance().socket.sendService(JSON.encode(obj)) ;
		}
	}

}